Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
@material/typography
Advanced tools
Typography classes, mixins, and variables for Material Components for the web
@material/typography is a package from the Material Design library that provides a set of typography styles and utilities to help developers implement consistent and visually appealing text styles in their web applications. It follows the Material Design guidelines for typography, ensuring that text elements are readable, accessible, and aesthetically pleasing.
Applying Typography Styles
This feature allows you to apply predefined typography styles to HTML elements. By importing the CSS file and adding the appropriate class to an element, you can style text according to Material Design guidelines.
import '@material/typography/dist/mdc.typography.css';
const myElement = document.createElement('div');
myElement.className = 'mdc-typography--headline1';
myElement.textContent = 'Hello, World!';
document.body.appendChild(myElement);
Customizing Typography
This feature allows you to customize typography styles programmatically. By using the `typography` function, you can define custom styles and apply them to elements.
import { typography } from '@material/typography';
const customTypography = typography({
fontFamily: 'Roboto, sans-serif',
fontSize: '16px',
fontWeight: '400',
lineHeight: '1.5'
});
const myElement = document.createElement('div');
myElement.style.cssText = customTypography;
myElement.textContent = 'Custom Typography';
document.body.appendChild(myElement);
The 'typography' package is a powerful toolkit for building beautiful websites with consistent typography. It provides a wide range of customization options and integrates well with various CSS-in-JS libraries. Compared to @material/typography, it offers more flexibility and customization options but does not strictly follow Material Design guidelines.
The 'styled-components' package allows you to write actual CSS code to style your components. It supports theming and dynamic styling, making it a versatile choice for managing typography in React applications. While it is not specifically focused on typography, it provides the tools to create and manage text styles effectively. It offers more flexibility than @material/typography but requires more setup for consistent typography.
The 'emotion' package is a library designed for writing CSS styles with JavaScript. It offers powerful and flexible styling capabilities, including support for theming and dynamic styles. Like styled-components, it is not focused solely on typography but provides the tools to manage text styles effectively. It offers more flexibility and customization compared to @material/typography but requires more effort to adhere to Material Design guidelines.
MDC typography is a CSS-only component that implements the Material Design typography guidelines, and makes them available to developers as CSS classes.
Note: Installation via the npm registry will be available after alpha.
<head>
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet">
</head>
<body class="mdc-typography">
<h1 class="mdc-typography--display4">Big header</h1>
</body>
Material Design typography uses the Roboto font, which we're loading from Google Fonts in the example above.
Note: You can load more font weights and styles if you wish, but
mdc-typography
only uses 300, 400 and 500.
The mdc-typography
class defines basic properties for text, such as the typeface and antialiasing settings.
Simply add the corresponding style class to format your text:
<body class="mdc-typography">
<h1 class="mdc-typography--display4">Big header</h1>
<p class="mdc-typography--body1">
A paragraph with <span class="mdc-typography--body2">emphasis</span>.
</p>
</body>
The full list of styles:
mdc-typography--display4
mdc-typography--display3
mdc-typography--display2
mdc-typography--display1
mdc-typography--headline
mdc-typography--title
mdc-typography--subheading
mdc-typography--body2
mdc-typography--body1
mdc-typography--caption
In order to minimize unexpected behavior, the style classes only specify font properties, such as size, weight and line height.
This means that while text will be correctly styled, it may not be correctly positioned. If you include the
mdc-typography--adjust-margin
class, though, positioning will be adjusted according to the style:
<body class="mdc-typography">
<h1 class="mdc-typography--display4 mdc-typography--adjust-margin">
Big header
</h1>
<p class="mdc-typography--body1 mdc-typography--adjust-margin">
A paragraph with
<span class="mdc-typography--body2 mdc-typography--adjust-margin">
emphasis
</span>.
</p>
</body>
Note: as the name implies,
mdc-typography--adjust-margin
will change the margin properties of the element it's applied to, in order to align text correctly. Because of this, it should only be used in a text context; using this property on UI elements such as buttons may cause them to be positioned incorrectly.
@include mdc-typography-base;
mdc-typography-base
defines the basic properties for Material Design typography, namely the font and aliasing
settings, without defining any particular font size or style.
@include mdc-typography(display4);
Applies one of the typography styles. Note that this includes the font family and aliasing definitions; you don't need
to include mdc-typography-base
as well.
The full list of styles:
display4
display3
display2
display1
headline
title
subheading
body2
body1
caption
@include mdc-typography(display4);
@include mdc-typography-adjust-margin(display4);
In order to minimize unexpected behavior, the style mixins only specify font properties, such as size, weight and line height.
This means that while text will be correctly styled, it may not be correctly positioned. If you include the
mdc-typography-adjust-margin
mixin as well, though, positioning will be adjusted according to the style.
Note: as the name implies,
mdc-typography-adjust-margin
will change the margin properties of the element it's applied to, in order to align text correctly. Because of this, it should only be used in a text context; using this property on UI elements such as buttons may cause them to be positioned incorrectly.
The list of styles is the same as for the mdc-typography
mixin:
display4
display3
display2
display1
headline
title
subheading
body2
body1
caption
FAQs
Typography classes, mixins, and variables for Material Components for the web
The npm package @material/typography receives a total of 370,111 weekly downloads. As such, @material/typography popularity was classified as popular.
We found that @material/typography demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 15 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.